package com.project.bookstore.book.controller;

import com.project.bookstore.book.entity.BookIndex;
import com.project.bookstore.book.mapper.BookMapper;
import com.project.bookstore.book.pojo.BookDetailVO;
import com.project.bookstore.book.pojo.BookIndexVO;
import com.project.bookstore.book.pojo.BookNameByKeyWordVO;
import com.project.bookstore.book.service.BookService;
import com.project.bookstore.common.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "书籍模块")
@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired(required = false)
    BookMapper bookMapper;

    /*@Autowired(required = false)
    BannerMapper bannerMapper;*/

    @Autowired
    BookService bookService;

    //首页书籍展示
    @GetMapping("/index")
    public CommonResult<List<BookIndexVO>> getBooksForIndex() {
    return bookService.getBooksForIndex();
    }

    @GetMapping("/related/{categoryId}")
    public CommonResult<List<BookIndexVO>> getBooksForRelated(@PathVariable Long categoryId){
        return bookService.getBooksByClassifyId(categoryId);
    }

    @GetMapping("/related/parent/{parentId}")
    public CommonResult<List<BookIndexVO>> getBooksForRelatedByParentId(@PathVariable Long parentId){
        return bookService.getBooksByClassifyIdByParentId(parentId);
    }

    @GetMapping("/{id}")
    public CommonResult<BookDetailVO> getBookDetailById(@PathVariable Long id) {
        return CommonResult.ok(bookService.getBookDetailById(id));
    }
}
